package com.elaticsearch.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @author:左泽林
 * @date:日期:2021-08-28-时间:15:59
 * @message:
 */
public class doc_delete {
    public static void main(String[] args) throws IOException {
        //创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("172.20.17.43",9200,"http"))
        );

        try {
            //查询数据
            DeleteRequest delete = new DeleteRequest();

            delete.index("user").id("1001"); //指定修改的id


            DeleteResponse response = esClient.delete(delete, RequestOptions.DEFAULT);

            System.out.println("===============操作结果==============");
            System.out.println(response.toString());
            System.out.println("===============操作结果==============");
        }catch (Exception e){
            System.out.println(e);
        }finally {
            esClient.close();
        }
    }
}
